local M = {
  "windwp/nvim-autopairs",
  enabled = true,
  event = "InsertEnter",
  --[[
after 与 before 控制插件加载顺序,
  -- 等效配置：
  {
    "nvim-telescope/telescope.nvim",
    dependencies = { "nvim-lua/plenary.nvim" }  -- 等价于 after = { "plenary.nvim" }
  }
  -- 更复杂的依赖链可用 dependencies + after 组合：
  {
    "A",
    dependencies = { "B" },  -- A 在 B 之后加载
    after = { "C" }          -- 同时 A 也在 C 之后加载
  }
  ]]
  dependencies = {
    "hrsh7th/nvim-cmp",
  },
}

M.config = function()
  require("nvim-autopairs").setup({
    check_ts = true, -- 基于Treesitter语法智能判断上下文
    disable_filetype = { "TelescopePrompt", "vim" }, -- 在特定场景禁用
    fast_wrap = {
      map = "<M-e>", -- Alt+e触发快速换行对齐
      chars = { "{", "[", "(", '"', "'" },
    },
    ts_config = {
      lua = { "string" }, -- it will not add a pair on that treesitter node
      javascript = { "template_string" },
      java = false, -- don't check treesitter on java
    },
  })

  -- 与代码补全引擎联动
  -- import nvim-autopairs completion functionality
  local cmp_autopairs = require("nvim-autopairs.completion.cmp")
  -- import nvim-cmp plugin (completions plugin)
  local cmp = require("cmp")
  -- make autopairs and completion work together
  cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
end

return M
